{% extends "admin/layout.html" %}

{% block head %} 
<title>{{ _(config["WEBSITE_NAME"]) }} - {{ _("Add Wiki Post") }}</title>
<script type="text/javascript" src="{{ url_for('static', filename='vendors/tinymce/tinymce.min.js') }}"></script>
<script type="text/javascript">
	tinymce.init({ 
		selector: "textarea",
		plugins : "advlist autolink link image lists charmap print preview textcolor emoticons directionality fullscreen table wordcount code",
		toolbar : "undo redo | styleselect | alignleft aligncenter alignright alignjustify ltr rtl | outdent indent blockquote removeformat bullist numlist | forecolor backcolor underline strikethrough italic bold | insertdatetime code preview emoticons table link image",
	});
	function checkTinymce() {
		var body = tinyMCE.activeEditor.getBody();
 		var content = tinyMCE.trim(body.innerText || body.textContent);
		if ((content.length == 0)) {
			window.alert("{{ _('Please fill content area.') }}");
			return false;
		} else {
			return true;
		}
	}
</script>
{% endblock %}

{% block body %}
<div class="right_col" role="main">
	{% if get_flashed_messages() %}
		<div class="alert alert-warning">
		</div>
		<div class="alert alert-danger alert-dismissible fade in" role="alert">
			<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  			<strong>{{ _("Warning!") }}</strong> {{ _("Address is not avaliable.") }}
		</div>
	{% endif %}
	<form action="{{ url_for('admin.posts_config') }}", method="POST" onsubmit="return checkTinymce();">
		<input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
		<input name="submit" type="hidden" value="add">
		<div class="row">
			<div class="form-group col-xs-6">
				<input class="form-control" placeholder="{{ _('Post Header') }}" type="text" autofocus id="post-header" name="post-header" required>
			</div>
			<div class="form-group col-xs-6">
				<select class="form-control" name="language" required>
					<option value="" disabled selected>{{ _("Language") }}</option>
					{% for lang in sorted(config["LANGUAGES"].keys()) %}
						<option>{{ _(lang) }}</option>
					{% endfor %}
				</select>
			</div>
		</div>
			<br>
		<textarea style="display: block !important; height: 400px;" placeholder="{{ _('Page Content') }}" rows="10" cols="100" name="content"></textarea><br>
		<div class="text-center">
			<input type="button" class="btn btn-md btn-default" onclick="tinyMCE.activeEditor.execCommand('mcePreview');" value="{{ _('Perview') }}">
	 		<input class="btn btn-md btn-default" type="submit" value="{{ _('Submit') }}">
	 	</div>
	</form>
</div>
{% endblock %}